package com.jt;

import org.slf4j.Logger; //java中的日志规范
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class ProviderApplication {
    //创建java中的日志对象(SLF4J是java中的日志规范,是日志对外的窗口,是门面设计模式)
    //目前市场上对SLF4J规范
    private static final Logger log =
            LoggerFactory.getLogger(ProviderController.class);
    public static void main(String[] args) {
        SpringApplication.run(ProviderApplication.class,args);
    }
    //@Value默认读取项目配置文件中的属性
    @Value("${server.port}")
    private String server;

    /*定义Controller对象(这个对象在spring mvc中给他的定义是handler),
    * 基于此对象处理客户端的请求*/

    @RefreshScope //这个注解描述类时,当配置中心数据发生变化会对属性进行重新初始化
    @RestController
    public class ProviderController{

        public ProviderController(){
            System.out.println("==ProviderController()==");
        }
        @GetMapping("/provider/echo/{msg}")
        public String doEcho(@PathVariable String msg){
            return server+"say:Hello Nacos Discovery"+msg;
        }
        @Value("${logging.level.com.jt:error}")
        private String logLevel;

        @GetMapping("/provider/dogetloglevel")
        public String doGetLogLevel(){
            //System.out.println("==="); //耗时
            //日志级别 trace<debug<info<warn<error
            log.trace("==trace==");//跟踪
            log.debug("==debug==");//调试
            log.info("==info==");//常规信息
            log.warn("==warn==");//警告
            log.error("==error==");//错误信息
            return "log level is " + logLevel;
        }

        @Value("${server.tomcat.threads.max:200}")
        private Integer maxThread;

        @GetMapping("/provider/doGetMaxThread")
        public String doGetMaxThread(){
            return "server.threads.max is  "+maxThread;
        }

        @Value("${page.pageSize:10}")
        private Integer pageSize;

        @GetMapping("/provider/doGetPageSize")
        public String doGetPageSize(){
            //return String.format()
            return "page size is "+pageSize;
        }


    }
}
